import 'package:flukit/flukit.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:testlzhu/utils/text_su_back.dart';
import 'package:testlzhu/view/test_page.dart';

import 'splash_page_logic.dart';

class SplashPageWidget extends GetView<SplashPageLogic> {
  final List<Widget> _bannerList = [];
  final _status = 2;

  @override
  Widget build(BuildContext context) {
   Get.put(SplashPageLogic());
    _initBannerData();
    return Material(
      child: Stack(
        children: <Widget>[
          Offstage(
            offstage: !(_status == 2),
            child: Swiper(
                autoStart: false,
                circular: false,
                indicator: CircleSwiperIndicator(
                  radius: 4.0,
                  padding: const EdgeInsets.only(bottom: 30.0),
                  itemColor: Colors.black26,
                ),
                children: _bannerList),
          ),
          Container(
            margin: const EdgeInsetsDirectional.only(end: 20),
            child: Align(
              alignment: Alignment.topRight,
              child: TextAa(
                3,
                90,
                textBack: TextBack(() {
                  _goMain();
                }),
              ),
            ),
          )
        ],
      ),
    );
  }

  void _initBannerData() {
    for (int i = 0, length = controller.state.guideList.length; i < length; i++) {
      if (i == length - 1) {
        _bannerList.add(Stack(
          children: <Widget>[
            Image.asset(controller.state.guideList[i]),
            Align(
              alignment: Alignment.bottomCenter,
              child: Container(
                margin: const EdgeInsets.only(bottom: 160.0),
                child: InkWell(
                  onTap: () {
                    _goMain();
                  },
                  child: const CircleAvatar(
                    radius: 48.0,
                    backgroundColor: Colors.indigoAccent,
                    child: Padding(
                      padding: EdgeInsets.all(2.0),
                      child: Text(
                        '立即体验',
                        textAlign: TextAlign.center,
                        style: TextStyle(color: Colors.white, fontSize: 16.0),
                      ),
                    ),
                  ),
                ),
              ),
            ),
          ],
        ));
      } else {
        _bannerList.add(Image.asset(
          controller.state.guideList[i],
          fit: BoxFit.fill,
          width: double.infinity,
          height: double.infinity,
        ));
      }
    }
  }

  void _goMain() {
    controller.topage();
  }
}
